<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
         // 设置定时器的名字来清除定时器
         var timeoutId1 = setTimeout(function() {
            console.log('nihao1');
        }, 2000);
        var timeoutId2 = setTimeout(function() {
            console.log('nihao2');
        }, 2000);
        console.log(timeoutId1);
        console.log(timeoutId2);
        clearTimeout(timeoutId1);//清除的是定时器的序号数，此时为1
        clearTimeout(timeoutId2);//清除的是定时器的序号数，此时为2
    </script>
</body>

</html>